/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-08-21
 * Time: 11:14
 * To BE A Better Person-2020-3-2
 */
class Solution {
    private int calexperience(int[] experience,int initialExperience){
        int maxIndex=0;
        int max=experience[0];
        int sum=0;

        for(int i=0;i<experience.length;i++){
            if(experience[i]>max){
                max=experience[i];
                maxIndex=i;
            }
        }

        //计算最大值之前的和
        for(int i=0;i<maxIndex;i++){
            sum+=experience[i];
        }

        return experience[maxIndex]-(sum+initialExperience)+1;
    }
    private int calEnergy(int[] energy,int initialEnergy){
        int sum=0;
        for(int i=0;i<energy.length;i++){
            sum+=energy[i];
        }
        return sum-initialEnergy+1;
    }
    public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
        int Enret=calEnergy(energy,initialEnergy);
        int Exret=calexperience(experience,initialExperience);
        int Enhour=0;
        int Exhour=0;
        if(Enret > 0){
            Enhour=Enret;
        }
        if(Exret > 0){
            Exhour=Exret;
        }

        return Exhour+Enhour;

    }

    public int searchInsert(int[] nums, int target) {
        int index=0;
        for(int i=0;i<nums.length;i++){
            if(nums[i]==target){
                return i;
            }else if(nums[i]>target){
                index=i;
                break;
            }
        }
        return index;
    }
}
public class Testdemo {
    public static void main(String[] args) {

        int[] arr={1,3,5,6};
        int t=2;
        Solution solution=new Solution();
        int ret=solution.searchInsert(arr,2);
        System.out.println(ret);
    }


}
